<?php
/**
 * 提现管理
 * edition ：v1
 * create time：2021-06-08
 * author: acker
 */
namespace App\Admin\Controllers\Member;

use App\Admin\Actions\Member\BatchOnShelf;
use App\Admin\Actions\Member\BatchOffShelf;
use App\Http\Controllers\Controller;
use App\Models\DataDictionaryModel;
use App\Models\yb\UserWithdrawalModel;
use Encore\Admin\Form;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Tab;
use Illuminate\Http\Request;


class UserWithdrawalController extends Controller
{
    use ModelForm;

    protected $header = '提现管理';

    /**
     * 工作状态列表
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->header);
            $content->description('列表');
            $content->body($this->grid());

        });
    }

    public function grid(){

        $grid = new Grid(new UserWithdrawalModel());

        $grid->model()->orderBy('created_at', 'DESC');

        $grid->column('id','提现编号')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $grid->column('user_nickname','用户昵称')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $grid->column('user_phone','用户电话')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $grid->column('amount','申请金额')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $grid->column('status','状态')->using([
            '0'=>'待审核',
            '1'=>'已打款',
            '2'=>'不通过',
        ], '未知')->dot([
            0 => 'danger',
            1 => 'info',
            2 => 'warning',
        ], 'success');

        $grid->column('created_at','申请时间')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        })->sortable();

        $grid->column('id','操作')->display(function($filed){

            return '<a href="javascript:void(0);" data-id="52625" class="grid-row-delete">
                        <button type="button" class="btn btn-danger btn-xs btn-flat">审核</button>
                    </a>';
        });

        //搜索
        $grid->filter(function($filter){
            $filter->column(1/2, function ($filter) {
                $filter->like('user_nickname','昵称');
                $filter->equal('status', '状态')->select([
                    '0'=>'待审核',
                    '1'=>'已打款',
                    '2'=>'不通过',
                ]);
            });
            $filter->column(1/2, function ($filter) {
                $filter->like('user_phone','电话');
                $filter->between('created_at', '申请时间')->datetime();

            });

            $filter->disableIdFilter();
        });

        $grid->disableActions();

        $grid->disableCreateButton();

        $grid->disableExport();

        $grid->fixColumns(1, -1);

        $grid->tools(function ($tools) {
            $tools->batch(function ($batch) {
                $batch->disableDelete();
            });
        });

        $grid->actions(function($actions){
            $actions->disableView();
        });

        $grid->paginate(10);

        return $grid;
    }

}